package Conversor.view;

import Conversor.controller.GerarArquivo;
import Conversor.model.Rumo;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;

/**
 * Tela para entrada de dados.
 * @author Tiago Bassetto
 * @since Classe criada em 24/06/2013
 */
public class ConverterRumo extends javax.swing.JDialog {

    /**
     * Creates new form ConverterRumo
     */
    
    String autoCAD = "_color ByLayer\r\npline\r\n10,10\r\n";
    String ultimoAzimute = "0d0'0";
    String corAtual = "Preto";
    
    public ConverterRumo(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        tfGrau = new javax.swing.JTextField();
        tfMinuto = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        tfSegundo = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        lbRumo = new javax.swing.JLabel();
        cbQuadrante = new javax.swing.JComboBox();
        btAdicionar = new javax.swing.JButton();
        tfMetro = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        cbRio = new javax.swing.JCheckBox();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        taAzimute = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        btSalvar = new javax.swing.JButton();
        btSair = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Conversor de Rumos - 1.0 BETA");
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Rumo"));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setText("º");

        tfGrau.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        tfGrau.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tfGrauFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfGrauFocusLost(evt);
            }
        });
        tfGrau.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfGrauKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tfGrauKeyTyped(evt);
            }
        });

        tfMinuto.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        tfMinuto.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tfMinutoFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfMinutoFocusLost(evt);
            }
        });
        tfMinuto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfMinutoKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tfMinutoKeyTyped(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("'");

        tfSegundo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        tfSegundo.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tfSegundoFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfSegundoFocusLost(evt);
            }
        });
        tfSegundo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfSegundoKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tfSegundoKeyTyped(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel3.setText("\"");

        lbRumo.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
        lbRumo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        cbQuadrante.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        cbQuadrante.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NE", "SE", "SW", "NW" }));
        cbQuadrante.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbQuadranteActionPerformed(evt);
            }
        });
        cbQuadrante.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                cbQuadranteFocusGained(evt);
            }
        });
        cbQuadrante.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                cbQuadranteKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cbQuadranteKeyTyped(evt);
            }
        });

        btAdicionar.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btAdicionar.setText("Adicionar");
        btAdicionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAdicionarActionPerformed(evt);
            }
        });
        btAdicionar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btAdicionarKeyPressed(evt);
            }
        });

        tfMetro.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        tfMetro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfMetroActionPerformed(evt);
            }
        });
        tfMetro.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tfMetroFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfMetroFocusLost(evt);
            }
        });
        tfMetro.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tfMetroKeyTyped(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel4.setText("m");

        cbRio.setText("Rio (Sem Azimute)");
        cbRio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbRioActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lbRumo, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cbRio))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(tfGrau, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfMinuto, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfSegundo, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbQuadrante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tfMetro, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addComponent(btAdicionar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jLabel4))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                .addComponent(tfGrau, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(tfMinuto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(tfSegundo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(cbQuadrante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(tfMetro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btAdicionar))
                            .addComponent(jLabel3))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbRumo, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(cbRio)))
                .addGap(10, 10, 10))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addGap(67, 67, 67))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Azimute"));

        taAzimute.setEditable(false);
        taAzimute.setColumns(20);
        taAzimute.setFont(new java.awt.Font("Monospaced", 0, 14)); // NOI18N
        taAzimute.setRows(5);
        taAzimute.setFocusable(false);
        jScrollPane1.setViewportView(taAzimute);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        btSalvar.setText("Salvar");
        btSalvar.setEnabled(false);
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });

        btSair.setText("Sair");
        btSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSairActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(135, 135, 135)
                .addComponent(btSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btSair, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btSalvar)
                    .addComponent(btSair))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(17, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void limparCampos(){
        tfGrau.setText("");
        tfMinuto.setText("");
        tfSegundo.setText("");
        tfMetro.setText("");
    }
    
    private void tfGrauKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfGrauKeyTyped
        String caracteres="0987654321";
        if(!caracteres.contains(evt.getKeyChar()+"")){
            evt.consume();
        }
    }//GEN-LAST:event_tfGrauKeyTyped

    private void tfMinutoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfMinutoKeyTyped
        String caracteres="0987654321";
        if(!caracteres.contains(evt.getKeyChar()+"")){
            evt.consume();
        }
    }//GEN-LAST:event_tfMinutoKeyTyped

    private void tfSegundoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfSegundoKeyTyped
        String caracteres="0987654321";
        if(!caracteres.contains(evt.getKeyChar()+"")){
            evt.consume();
        }
    }//GEN-LAST:event_tfSegundoKeyTyped

    private void cbQuadranteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbQuadranteActionPerformed
        lbRumo.setText(tfGrau.getText() + "º" + tfMinuto.getText() + "'" + tfSegundo.getText() + "\" " + cbQuadrante.getSelectedItem());
    }//GEN-LAST:event_cbQuadranteActionPerformed

    private void cbQuadranteKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cbQuadranteKeyTyped
    }//GEN-LAST:event_cbQuadranteKeyTyped

    private void btAdicionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAdicionarActionPerformed
        if(cbRio.isSelected()){
            if(tfMetro.getText().equals("")){
                JOptionPane.showMessageDialog(null, "Digite um valor para a distância!");
                tfMetro.requestFocus();
            }
            else{
                Rumo r = new Rumo();
                taAzimute.setText(taAzimute.getText() + r.converterDistancia(Float.parseFloat(tfMetro.getText())));
                if(corAtual.equals("Preto")){
                    corAtual = "Azul";
                    autoCAD = autoCAD + r.mudarCor(corAtual);
                }
                autoCAD = autoCAD + r.gerarCodigo(Float.parseFloat(tfMetro.getText()), ultimoAzimute);
                tfMetro.requestFocus();
                limparCampos();
                btSalvar.setEnabled(true);
            }
        }
        else{
            if(tfGrau.getText().equals("")){
                JOptionPane.showMessageDialog(null, "Digite um valor para grau!");
                tfGrau.requestFocus();
            }
            else if(tfMinuto.getText().equals("")){
                JOptionPane.showMessageDialog(null, "Digite um valor para minuto!");
                tfMinuto.requestFocus();
            }
            else if(tfSegundo.getText().equals("")){
                JOptionPane.showMessageDialog(null, "Digite um valor para segundo!");
                tfSegundo.requestFocus();
            }
            else if(tfMetro.getText().equals("")){
                JOptionPane.showMessageDialog(null, "Digite um valor para a distância!");
                tfMetro.requestFocus();
            }
            else{
                Rumo r = new Rumo();
                r.setGrau(Integer.parseInt(tfGrau.getText()));
                r.setMinuto(Integer.parseInt(tfMinuto.getText()));
                r.setSegundo(Integer.parseInt(tfSegundo.getText()));
                r.setQuadrante((String) cbQuadrante.getSelectedItem());
                r.setDistancia(Float.parseFloat(tfMetro.getText()));
                taAzimute.setText(taAzimute.getText() + r.converterRumo(r));
                ultimoAzimute = r.gerarCodigo(r, 1);
                if(corAtual.equals("Azul")){
                    corAtual = "Preto";
                    autoCAD = autoCAD + r.mudarCor(corAtual);
                }
                autoCAD = autoCAD + r.gerarCodigo(r);
                tfGrau.requestFocus();
                limparCampos();
                btSalvar.setEnabled(true);
            }
        }
    }//GEN-LAST:event_btAdicionarActionPerformed

    private void btSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSairActionPerformed
        System.exit(0);
    }//GEN-LAST:event_btSairActionPerformed

    private void cbQuadranteFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cbQuadranteFocusGained
        cbQuadranteActionPerformed(null);
    }//GEN-LAST:event_cbQuadranteFocusGained

    private void btAdicionarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btAdicionarKeyPressed
        btAdicionarActionPerformed(null);
    }//GEN-LAST:event_btAdicionarKeyPressed
    
    private void tfGrauFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfGrauFocusLost
        if(tfGrau.getText().equals("")){
            tfGrau.setText("0");
        }
        else if(Integer.parseInt(tfGrau.getText()) > 90){
            JOptionPane.showMessageDialog(null, "Digite um valor menor ou igual a 90º");
            tfGrau.requestFocus();
            tfGrau.setText("");
        }
    }//GEN-LAST:event_tfGrauFocusLost

    private void tfMinutoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfMinutoFocusLost
        if(tfMinuto.getText().equals("")){
            tfMinuto.setText("0");
        }
        else if(Integer.parseInt(tfMinuto.getText()) > 59){
            JOptionPane.showMessageDialog(null, "Digite um valor menor ou igual a 59'");
            tfMinuto.requestFocus();
            tfMinuto.setText("");
        }
    }//GEN-LAST:event_tfMinutoFocusLost

    private void tfSegundoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfSegundoFocusLost
        if(tfSegundo.getText().equals("")){
            tfSegundo.setText("0");
        }
        else if(Integer.parseInt(tfSegundo.getText()) > 59){
            JOptionPane.showMessageDialog(null, "Digite um valor menor ou igual a 59\"");
            tfSegundo.requestFocus();
            tfSegundo.setText("");
        }
    }//GEN-LAST:event_tfSegundoFocusLost

    private void tfMetroKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfMetroKeyTyped
        String caracteres="0987654321.";
        if(!caracteres.contains(evt.getKeyChar()+"")){
            evt.consume();
        }
    }//GEN-LAST:event_tfMetroKeyTyped

    private void tfMetroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfMetroActionPerformed
        btAdicionarActionPerformed(evt);
    }//GEN-LAST:event_tfMetroActionPerformed

    private void tfSegundoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfSegundoFocusGained
        tfSegundo.selectAll();
    }//GEN-LAST:event_tfSegundoFocusGained

    private void tfMinutoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfMinutoFocusGained
        tfMinuto.selectAll();
    }//GEN-LAST:event_tfMinutoFocusGained

    private void tfGrauFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfGrauFocusGained
        tfGrau.selectAll();
    }//GEN-LAST:event_tfGrauFocusGained

    private void tfMetroFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfMetroFocusGained
        tfMetro.selectAll();
    }//GEN-LAST:event_tfMetroFocusGained

    private void cbQuadranteKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cbQuadranteKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {  
            tfMetro.requestFocus();
        }
    }//GEN-LAST:event_cbQuadranteKeyPressed

    private void tfGrauKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfGrauKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {  
            tfMinuto.requestFocus();
        }
    }//GEN-LAST:event_tfGrauKeyPressed

    private void tfMinutoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfMinutoKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {  
            tfSegundo.requestFocus();
        }
    }//GEN-LAST:event_tfMinutoKeyPressed

    private void tfSegundoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfSegundoKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {  
            cbQuadrante.requestFocus();
        }
    }//GEN-LAST:event_tfSegundoKeyPressed

    private void tfMetroFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfMetroFocusLost
        if(Float.parseFloat(tfMetro.getText()) <= 0){
            JOptionPane.showMessageDialog(null, "A distância deve ser maior que 0!");
            tfMetro.requestFocus();
            tfMetro.setText("");
        }
    }//GEN-LAST:event_tfMetroFocusLost

    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed
        GerarArquivo c = new GerarArquivo();
        c.criarArquivo(autoCAD + "\r\nZOOM\r\nE\r\n", "AutoCAD Script", ".scr");
    }//GEN-LAST:event_btSalvarActionPerformed

    private void cbRioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbRioActionPerformed
        if(cbRio.isSelected()){
            tfGrau.setEnabled(false);
            tfMinuto.setEnabled(false);
            tfSegundo.setEnabled(false);
            cbQuadrante.setEnabled(false);
            tfMetro.requestFocus();
        }
        else{
            tfGrau.setEnabled(true);
            tfMinuto.setEnabled(true);
            tfSegundo.setEnabled(true);
            cbQuadrante.setEnabled(true);
            tfGrau.requestFocus();
        }
    }//GEN-LAST:event_cbRioActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ConverterRumo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ConverterRumo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ConverterRumo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ConverterRumo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                ConverterRumo dialog = new ConverterRumo(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAdicionar;
    private javax.swing.JButton btSair;
    private javax.swing.JButton btSalvar;
    private javax.swing.JComboBox cbQuadrante;
    private javax.swing.JCheckBox cbRio;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lbRumo;
    private javax.swing.JTextArea taAzimute;
    private javax.swing.JTextField tfGrau;
    private javax.swing.JTextField tfMetro;
    private javax.swing.JTextField tfMinuto;
    private javax.swing.JTextField tfSegundo;
    // End of variables declaration//GEN-END:variables
}
